<template>
<div style="height:600px;overflow-y: auto; ">
  <div class="head_title">基本信息</div>
  <el-form ref="form" :model="form" :rules="rules" style="margin-top: 16px;" size="small" label-width="160px">
	<el-form-item label="客户编号"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.custNum" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="客户名称"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.custName" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="证件类型"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.certificateType" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="证件号码"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.certificateNum" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="社会保险号"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.socialSecurityNum" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="缴纳城市"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.payCity" style="width: 370px;"/>
    </el-form-item>
	 <el-form-item label="性别"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.sex" style="width: 370px;"/>
    </el-form-item>
    <el-form-item label="生日"  prop="deptNum" style="display:inline-block;width:48%;">
		 <el-form-item prop="date1">
					<el-date-picker  type="date"   v-model="form.birthday" style="width: 370px;"></el-date-picker>
		</el-form-item>
    </el-form-item>
	<el-form-item label="民族"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.nationality" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="婚姻状况"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.maritalStatus" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="家庭住址"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.homeAddr" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="户籍住址"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.householdAddr" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="国家"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.country" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="最高学历"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.highestDegree" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="毕业学校"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.graduatedSchool" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="电子邮箱"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.email" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="电话"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.phone" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="个人收入"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.personalIncome" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="工资账号"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.payrollAccount" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="家庭月收入"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.homeMonthIncome" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="单位行业"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.deptIndustry" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="单位名称"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.deptName" style="width: 370px;"/>
    </el-form-item>
    <el-form-item label="公司地址"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.companyAddr" style="width: 370px;"/>
    </el-form-item>
	 <el-form-item label="单位电话"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.deptTelephone" style="width: 370px;"/>
    </el-form-item>
	 <el-form-item label="信用等级"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.creditRate" style="width: 370px;"/>
    </el-form-item>
	 <el-form-item label="是否农业"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.isFarming" style="width: 370px;"/>
    </el-form-item>
	 <el-form-item label="录入单位"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.createDept" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="备注"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.remark" style="width: 370px;"/>
    </el-form-item>
     <el-form-item label="录入日期"  prop="deptNum" style="display:inline-block;width:48%;">
		 <el-form-item prop="date1">
					<el-date-picker  type="date"   v-model="form.createDate" style="width: 370px;"></el-date-picker>
		</el-form-item>
    </el-form-item>

	<el-form-item label="录入人"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.createUser" style="width: 370px;"/>
    </el-form-item>
    <!-- <el-form-item label="appID" prop="appID" class="two">
      <el-input v-model="form.appID" style="width: 40%"/>
    </el-form-item>
    <el-form-item label="商家账号" prop="sysServiceProviderId"  class="two">
      <el-input v-model="form.sysServiceProviderId" style="width: 40%;"/>
    </el-form-item>
    <el-form-item label="商户私钥" prop="privateKey"  class="two">
      <el-input v-model="form.privateKey" type="password" style="width: 40%;"/>
    </el-form-item>
    <el-form-item label="支付宝公钥" prop="publicKey"  class="two">
      <el-input v-model="form.publicKey" type="password" style="width: 40%;"/>
    </el-form-item>
    <el-form-item label="回调地址" prop="returnUrl"  class="two">
      <el-input v-model="form.returnUrl" style="width: 40%;"/>
    </el-form-item>
    <el-form-item label="异步通知" prop="notifyUrl"  class="two">
      <el-input v-model="form.notifyUrl" style="width: 40%;"/>
    </el-form-item> -->
    <!-- <el-form-item label="">
      <el-button :loading="loading" size="medium" type="primary" @click="doSubmit">保存配置</el-button>
    </el-form-item> -->
  </el-form>				
     
	

	  <el-dialog :append-to-body="true" :close-on-click-modal="false" :before-close="cancelAdd" :visible.sync="dialog" title='新增'  width="650px">
		     <el-form ref="forms" :model="addForm" :rules="addRules" size="small" label-width="150px">
				    <el-form-item label="证件国别" prop="cardCountry">
						<el-input v-model="addForm.cardCountry" style="width: 370px;"/>
					</el-form-item>
					<el-form-item label="证件类型" prop="cardType">
						<el-input v-model="addForm.cardType" style="width: 370px;"/>
					</el-form-item>
					<el-form-item label="证件编号" prop="cardNum">
						<el-input v-model="addForm.cardNum" style="width: 370px;"/>
					</el-form-item>
					<el-form-item label="证件到期日期" prop="cardEndDate">
						<!-- <el-input v-model="addForm.cardEndDate" style="width: 370px;"/> -->
						<el-date-picker  type="date" placeholder="选择日期" v-model="addForm.cardEndDate" style="width: 370px;"  value-format="timestamp"></el-date-picker>
					</el-form-item>
					 <!-- <el-form-item label="成立时间" style="display:inline-block;width:48%;">
			<el-form-item prop="date1">
					<el-date-picker  type="date" placeholder="选择日期" v-model="form.foundTime" style="width: 370px;"  value-format="timestamp"></el-date-picker>
			</el-form-item>			
	  </el-form-item> -->
					<el-form-item label="证件状态" prop="cardStatus"> 
						<el-input v-model="addForm.cardStatus" style="width: 370px;"/>
					</el-form-item>
					<el-form-item label="证件发布城市" prop="cardPublishCity">
						<el-input v-model="addForm.cardPublishCity" style="width: 370px;"/>
					</el-form-item>
					<el-form-item label="是否主证件" prop="isMainCard">
						<el-input v-model="addForm.isMainCard" style="width: 370px;"/>
					</el-form-item>
			 </el-form>
			 <div slot="footer" class="dialog-footer">
				<el-button type="text" @click="cancelAdd">取消</el-button>
				<el-button :loading="loading" type="primary" @click="addCredentials">确认</el-button>
			</div>
	  </el-dialog>
  </div>
</template>

<script>
import { get, update } from '@/api/alipay'
import { general,list,credentials,addCredentials,effective} from '@/api/custPerBaseinfo'
import initData from '@/mixins/initData'
import { parseTime } from '@/utils/index'
import checkPermission from '@/utils/permission'
export default {
  mixins: [initData],
  data() {
    return {
	  dialog:false,
	  loading: false,
	  addLoading:false,
	  id:'',
	  form: { 
		 custNum:'',
		 custName:'',
		 certificateType:'',
		 certificateNum:'',
		 socialSecurityNum:'',
		 payCity:'',
		 sex:'',
		 birthday:'',
		 nationality:'',
		 maritalStatus:'',
		 homeAddr:'',
		 householdAddr:'',
		 country:'',
		 highestDegree:'',
		 graduatedSchool:'',
		 email:'',
		 phone:'',
		 personalIncome:'',
		 payrollAccount:'',
		 homeMonthIncome:'',
		 deptIndustry:'',
		 deptName:'',
		 companyAddr:'',
		 deptTelephone:'',
		 creditRate:'',
		 isFarming:'',
		 createDept:'',
		 remark:'',
		 createDate:'',
		 createUser:''
	  },
		  reqForm:{
			page: 0, 
			size: 10,
			sort:'id,desc',
			id:''
		},
		reqLoading:true,
		reqId:'',
		reqIds:[],
	    addForm:{
		   cardCountry:'',
		   cardType:'',
		   cardNum:'',
		   cardEndDate:'',
		   cardStatus:'',
		   cardPublishCity:'',
		   isMainCard:''
		},
		addRules: {
				cardCountry: [
				  { required: true, message: '请输入证件国别', trigger: 'blur' }
				],
				cardType: [
				  { required: true, message: '请输入证件类型', trigger: 'blur' }
				],
				cardNum: [
				  { required: true, message: '请输入证件编号', trigger: 'blur' }
				],
				cardEndDate: [
				  { required: true, message: '请输入证件到期日期', trigger: 'blur' }
				],
				cardStatus: [
				  { required: true, message: '请输入证件状态', trigger: 'blur' }
				],
				cardPublishCity: [
				  { required: true, message: '请输入证件发布城市', trigger: 'blur' }
				],
		        isMainCard: [
				  { required: true, message: '请输入是否主证件', trigger: 'blur' }
				]

		},

		effectiveParams:{
		   id:'',
		   cardStatus:''
		},
      rules: {
        appID: [
          { required: true, message: '请输入appID', trigger: 'blur' }
        ],
        sysServiceProviderId: [
          { required: true, message: '请输入商家账号', trigger: 'blur' }
        ],
        privateKey: [
          { required: true, message: '商户私钥不能为空', trigger: 'blur' }
        ],
        publicKey: [
          { required: true, message: '支付宝公钥不能为空', trigger: 'blur' }
        ],
        returnUrl: [
          { required: true, message: '回调地址不能为空', trigger: 'blur' }
        ],
        notifyUrl: [
          { required: true, message: '回调地址不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
	  console.log('id----',this.$route.params.id)
	  //this.id = this.$route.params.id
	  
	  console.log('id--------------',this.id)
	  	setTimeout(() => {
				 this.id = sessionStorage.getItem('perCustId')
				 this.reqForm.id = sessionStorage.getItem('perCustId')
				 console.log('this.id',this.id)
				 this.loading = true
				 let that = this
                 general(this.id).then(res => {
					   this.loading = false
					  // that.form = res
                      this.form = {
						    custNum:res.custNum,
							custName:res.custName,
							certificateType:res.certificateType,
							certificateNum:res.certificateNum,
							socialSecurityNum:res.socialSecurityNum,
							payCity:res.payCity,
							sex:res.sex,
							birthday:res.birthday,
							nationality:res.nationality,
							maritalStatus:res.maritalStatus,
							homeAddr:res.homeAddr,
							householdAddr:res.householdAddr,
							country:res.country,
							highestDegree:res.highestDegree,
							graduatedSchool:res.graduatedSchool,
							email:res.email,
							phone:res.phone,
							personalIncome:res.personalIncome,
							payrollAccount:res.payrollAccount,
							homeMonthIncome:res.homeMonthIncome,
							deptIndustry:res.deptIndustry,
							deptName:res.deptName,
							companyAddr:res.companyAddr,
							deptTelephone:res.deptTelephone,
							creditRate:res.creditRate,
							isFarming:res.isFarming,
							createDept:res.createDept,
							remark:res.remark,
							createDate:res.createDate,
							createUser:res.createUser
					  }
					   console.log('res',res)
                 }).catch(err => {
                       this.loading = false
                       console.log(err.response.data.message)
				}) 

         }, 500)
	  
  },
  methods: {
	   parseTime,
	   checkPermission,
    init() {
	  
        // this.delLoading = true
      general(this.id).then(res => {
        // this.delLoading = false
        // this.$refs[id].doClose()
        // this.dleChangePage()
        // this.init()
        // this.$notify({
        //   title: '删除成功',
        //   type: 'success',
        //   duration: 2500
        // })
      }).catch(err => {
        // this.delLoading = false
        // this.$refs[id].doClose()
        // console.log(err.response.data.message)
      })



    //   get().then(res => {
    //     this.form = res
    //   })
	},
	handleSelectionChange(val) {
		  console.log('val',val)
		   val.forEach((v) => {
               this.reqIds.push(v.id)
		   });
		   console.log('ids',this.reqIds)
		   this.reqId = this.reqIds.toString()
		   this.reqIds = []
	},
	add(){
		this.dialog = true;
	},
	cancelAdd(){
		this.resetForm()
	},
	resetForm() {
      this.dialog = false
	  this.$refs['forms'].resetFields()
	  this.addForm ={
		   cardCountry:'',
		   cardType:'',
		   cardNum:'',
		   cardEndDate:'',
		   cardStatus:'',
		   cardPublishCity:'',
		   isMainCard:''
	  }
	},
	addCredentials(){
		  this.$refs['forms'].validate((valid) => {
				if (valid) {
				this.addLoading = true
				addCredentials(this.addForm).then(res => {
					this.$notify({
					title: '新增成功',
					type: 'success',
					duration: 2500
					})
					this.credentials();
					this.addLoading = false
					this.dialog = false;
				}).catch(err => {
					this.addLoading = false
					console.log(err.response.data.message)
				})
				} else {
				return false
				}
			})
	},
	credentials(){
              credentials(this.reqForm).then(res => {
					this.total = res.totalElements
					this.data = res.content
					setTimeout(() => {
						this.reqLoading = false
					}, 170)
				}).catch(err => {
					this.reqLoading = false
					console.log(err.response.data.message)
				})
	},
	 effective(){
		 this.effectiveParams.id = this.reqId
		 this.effectiveParams.cardStatus = '1' 
		 if(this.effectiveParams.id == ''){
			this.$message.warning('请选择某个复选框') 
			return;
		 }
        effective(this.effectiveParams).then(res => {
            this.$notify({
              title: '已生效',
              type: 'success',
              duration: 2500
			})
			this.credentials();
            // this.loading = false
          }).catch(err => {
            // this.loading = false
            console.log(err.response.data.message)
          })
	 }, 

	 invalid(){
		 this.effectiveParams.id = this.reqId
		 this.effectiveParams.cardStatus = '0' 
		 if(this.effectiveParams.id == ''){
			this.$message.warning('请选择某个复选框') 
			return;
		 }
        effective(this.effectiveParams).then(res => {
            this.$notify({
              title: '已失效',
              type: 'success',
              duration: 2500
			})
			this.credentials();
            // this.loading = false
          }).catch(err => {
            // this.loading = false
            console.log(err.response.data.message)
          })
	 }, 

    doSubmit() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          this.loading = true
          update(this.form).then(res => {
            this.$notify({
              title: '修改成功',
              type: 'success',
              duration: 2500
            })
            this.loading = false
          }).catch(err => {
            this.loading = false
            console.log(err.response.data.message)
          })
        } else {
          return false
        }
      })
    }
  }
}
</script>

<style scoped> 
  .head_title{
    height:40px;line-height:40px;border-bottom: 2px solid #ce2731;color:#ce2731
  }
  .space{
	  margin-top:30px;
	  margin-bottom:10px
  }
   .one{
	   display:inline-block;
	   width:86.5%;
   }
   .two{
	   display:inline-block;
	   width:50%;
	
   }


</style>
